# coding:utf-8
import configparser
import os

from selenium import webdriver
import time


class Qzone:
    def __init__(self):
        self.url = 'https://qzone.qq.com/'
        self.driver = None

    def run(self):
        self.driver = webdriver.Chrome()
        self.driver.get(self.url)
        time.sleep(3)

        _el_iframe = self.driver.find_element_by_xpath('//*[@id="login_frame"]')
        self.driver.switch_to.frame(_el_iframe)
        _el = self.driver.find_element_by_xpath('//*[@id="switcher_plogin"]')
        _el.click()
        time.sleep(2)

        user_pswd_cfg = os.environ['user_pswd']
        cf = configparser.ConfigParser()
        cf.read(user_pswd_cfg)
        _user = cf.get('qq', 'qq_user')
        _pswd = cf.get('qq', 'qq_pswd')
        _el_user = self.driver.find_element_by_xpath('//*[@id="u"]')
        _el_user.send_keys(_user)
        _el_pwd = self.driver.find_element_by_xpath('//*[@id="p"]')
        _el_pwd.send_keys(_pswd)

        # 点击登陆
        _el_sub = self.driver.find_element_by_xpath('//*[@id="login_button"]')
        _el_sub.click()
        time.sleep(2)
        _el_sub.click()


def main():
    qz = Qzone()
    qz.run()


if __name__ == '__main__':
    main()
